<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      v-show="showSearch"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="家长姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入家长姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家长昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入家长昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴费标题" prop="payName">
        <el-input
          v-model="queryParams.payName"
          placeholder="请输入缴费标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级">
        <el-cascader
          clearable
          :props="props"
          v-model="queryParams.remark"
          popper-class="pc-sel-area-cascader"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="pdList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        :index="table_index"
        width="50"
        align="center"
      >
      </el-table-column>
      <el-table-column label="缴费单号" align="center" prop="pdId" />
      <el-table-column label="缴费内容标题" align="center" prop="pay.payName" />
      <el-table-column label="缴费金额" align="center" prop="pay.payMoney" />
      <el-table-column
        label="缴费家长姓名"
        align="center"
        prop="sysUser.userName"
      />
      <el-table-column
        label="缴费家长昵称"
        align="center"
        prop="sysUser.nickName"
      />
      <el-table-column
        label="缴费家长电话"
        align="center"
        prop="sysUser.phonenumber"
      />
      <el-table-column
        label="缴费家长邮箱"
        align="center"
        prop="sysUser.email"
      /><el-table-column
        label="缴费时间"
        align="center"
        prop="createTime"
      /><el-table-column label="缴费孩子班级" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleContent(scope.row)"
            >查看内容
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--查看公告内容-->
    <el-dialog :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form">
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-tag size="medium" style="font-size: 15px">{{
                form.payName
              }}</el-tag>
            </el-form-item>
          </el-col>

          <el-col :span="24" style="margin-top: -22px">
            <el-divider
              ><i class="el-icon-star-off" style="margin-right: 3px"></i
              >缴费标题</el-divider
            >
          </el-col>
          <el-col :span="24" style="margin-top: 10px">
            <el-form-item>
              <el-card>
                <el-col>
                  <div
                    v-html="form.payContent"
                    class="content demo-image__lazy"
                  ></div>
                </el-col>
              </el-card>
            </el-form-item>
          </el-col>
          <el-col :span="24" style="margin-top: -22px">
            <el-divider
              ><i class="el-icon-star-off" style="margin-right: 3px"></i
              >缴费内容</el-divider
            >
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listRecordPd, delPd } from "@/api/money/pd";
import { studentClass } from "@/api/class/roster";
export default {
  name: "Detail",
  data() {
    return {
      buttonLoading: false,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      noTotal: 0,
      // 缴费表格数据
      pdList: [],
      noPdList: [],
      // 显示搜索条件
      showSearch: true,
      props: {
        lazy: true,
        lazyLoad(node, resolve) {
          const { level } = node;
          let parentId;
          if (node.value) {
            parentId = node.value;
          } else {
            parentId = 0;
          }
          studentClass({ parentId: parentId }).then((res) => {
            const nodes = res.data.map((v) => ({
              value: v.deptId,
              label: v.typeName,
              leaf: level === 1,
            }));
            resolve(nodes);
          });
        },
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: 1,
        userName: undefined,
        nickName: undefined,
        payName: undefined,
        remark: undefined,
      },
      // 表单参数
      form: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      listRecordPd(this.queryParams).then((response) => {
        console.log(response);
        this.pdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //序号换页问题
    table_index(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.queryParams.userName == "") {
        this.queryParams.userName = undefined;
      }
      if (this.queryParams.nickName == "") {
        this.queryParams.nickName = undefined;
      }
      if (this.queryParams.payName == "") {
        this.queryParams.payName = undefined;
      }
      if (this.queryParams.remark != undefined) {
        this.queryParams.remark =
          this.queryParams.remark[this.queryParams.remark.length - 1];
      }
      console.log(this.queryParams);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /* 菜单重置 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.pdId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.pdId || this.ids;
      this.$modal
        .confirm('是否确认删除缴费记录单号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delPd(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 查询公告内容按钮操作 */
    handleContent(row) {
      this.loading = true;
      this.reset();
      const id = row.pdId || this.ids;
      // console.log(this.pdList);
      for (let i = 0; i < this.pdList.length; i++) {
        if (id == this.pdList[i].pdId) {
          this.form = this.pdList[i].pay;
          this.loading = false;
          break;
        }
      }
      this.open = true;
      this.title = row.pay.payName;
      // });
    },
  },
};
</script>

<style lang="less" scoped>
.demo-image__lazy {
  height: 600px;
  overflow-y: auto;
}
.demo-image__lazy .el-image {
  display: block;
  min-height: 200px;
  margin-bottom: 10px;
}
.demo-image__lazy .el-image:last-child {
  margin-bottom: 0;
}
.el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}
.content {
  text-indent: 2em;
}
</style>